*------------------------------------------------------------------------------*
			*** FIGURE S11b. POLLUTION IN MUNICH ACROSS ELECTION DATES ***
*------------------------------------------------------------------------------*

***Election dates in estimation sample
use "${tempdata}kreise_complete_all.dta", clear

*Keep estimation sample
keep if samplePM10_allcontrols == 1

*Keep Bavaria
keep if Land == "Bayern"

*Keep election dates
bys election_date: keep if _n == 1
keep election_date

*Save file with election dates
save "${tempdata}election_dates_bavaria.dta", replace

*------------------------------------------------------------------------------*

**Pollution in Munich on election dates
use "${rawdata}pollution/pollution_UBA_d_19902019.dta", clear

*Keep relevant variables
keep station year month day PM10_ug

*Gen date and day of the week
gen election_date = mdy(month, day, year)
format election_date %td

*Keep Bavarian stations
keep if substr(station, 1, 4) == "DEBY"

*Merge election dates
merge m:1 election_date using "${tempdata}election_dates_bavaria.dta", keep(master match)
keep if _merge == 3
drop _merge

*Add station coordinated
merge m:1 station using "${rawdata}pollution/meta_station_UBA.dta", keepusing(latitude longitude) keep(master match) nogen

*Add Munich coordinates
gen latitude_kreis = 48.13642
gen longitude_kreis = 11.57755

*------------------------------------------------------------------------------*

**Distance
distance latitude_kreis longitude_kreis latitude_d longitude_d , a(kreis) b(station)

*Keep stations within 30km
keep if dist_KRST <= 30

*Keep stations with valid PM10
keep if PM10_ug != .

**Inverse-distance weighted PM10
*Create weights
gen double weight = 1/dist_KRST
bys election_date: egen double weight_tot = total(weight)
replace weight = weight/weight_tot
drop weight_tot

*Weighted mean
bys election_date: egen double PM10_weight = total(PM10_ug*weight)
bys election_date: keep if _n==1

rename PM10_weight PM10_weight_30km

*Gen PM10 in tens of micrograms
gen PM10_weight_10ug = PM10_weight_30km / 10

*Label election dates
label define election_dates 15605 "22Sep2002" 15969 "21Sep2003" 16697 "18Sep2005" 17803 "28Sep2008" 18167 "27Sep2009" 19616 "15Sep2013" 19623 "22Sep2013" 21086 "24Sep2017" 21471 "14Oct2018"
label values election_date election_dates

*------------------------------------------------------------------------------*

**Graph
graph hbar (asis) PM10_weight_10ug, over(election_date, label(angle(fourtyfive))) ytitle(PM10 (10 {&mu}g/m{sup:3})) graphregion(color(white))

graph export "${outputs}figure_S11b.pdf", as(pdf) replace

*------------------------------------------------------------------------------*

clear

exit
